<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
class Output Extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		// $this->page_auth->secure_page();
		
	}

	public function fetch_events($event_id = '00000')
	{
		$this->load->model('M_calendar','mcal');
		$result = $this->mcal->get_event($event_id);
		$html = '';
		if($result)
		{
			$from = new DateTime($result->event_start);
			$end = new DateTime($result->event_end);
			$end->modify('-1 Day');
			$diff = $from->diff($end);
			$html.= '<div>';
				$html.= '<label class="label">Name of Event</label>';
				$html.= '<p>'.htmlentities($result->event_name).'</p>';
			$html.= '</div>';
			$html.= '<hr>';

			$html.= '<div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">Start Date</label>';
					$html.= '<p>'.$from->format('M d, Y').'</p>';
				$html.= '</div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">End Date</label>';
					$html.= '<p>'.$end->format('M d, Y').'</p>';
				$html.= '</div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">Days</label>';
					$html.= '<p>'.intval($diff->days + 1).'Days</p>';
				$html.= '</div>';
			$html.= '</div>';
			$html.= '<hr>';
			$html.= '<div>';
				$html.= '<label class="label">Description</label>';
				$html.= '<p>'.htmlentities($result->event_desc).'</p>';
			$html.= '</div>';
			$html.= '<hr>';
			$html.= '<div>';
				$html.= '<div style="width:49%;display:inline-block;">';
					$html.= '<label class="label">Posted By</label>';
					$html.= '<p>'.$result->event_created_by.'</p>';
				$html.= '</div>';
				$html.= '<div style="width:49%;display:inline-block;">';
					$html.= '<label class="label">Posted On</label>';
					$html.= '<p>'.$result->created.'</p>';
				$html.= '</div>';
			$html.= '</div>';
		}else{
			$html .= '<div class="alert-box">Unable to get events.</div>';
		}
		echo $html;
	}

	public function read_commendation($hash = '')
	{
		$x = $this->hs->decrypt($hash);
		if($x)
		{
			$this->load->model('M_student','ms');
			$result = $this->ms->read_commendation($x[0]);
			if($result)
			{
				$log = 'Successful';
			}else{
				$log = 'Error occured';
			}
			$res =  ['status'=>$result,'log'=>$log];
		}else{
			$res =  ['status'=>false,'log'=>'Invalid key sent.'];
		}

		header('Content-Type: application/json');
		echo json_encode($res);
		exit();
	}
	
	function get_section_data()
	{
		$this->load->model(array('M_sections'));
		$id = intval($this->input->get('id'));
		$data = $this->M_sections->get_section_by_grade_level($id);


		if($data == 'NOBLOCK')
		{
			$template = '<tr><td colspan="4" style="text-align:center;font-size:15px;font-weight:bold;color:#f00">No block has been set for this grade level. Please continue.</td></tr>';
			$template .= '<input type="hidden" value="noblock" name="section">';
		
		}elseif($data)
		{
			$template = '';
			
			if(!empty($data))
			{	
				foreach ($data as $data)
				{
					$template .= '<tr><td class="center"><input type="radio" name="section" title="'.$data->block_name.'" class="student_block" value="'.$data->id.'" required></td>
									  <td class="center">'.$data->block_name.'</td>
									  <td class="center">'.$data->block_desc.'</td>
									  <td class="center">max load</td>
								  </tr>';
				}
			}else
			{
				$template .= '<tr>
								<td colspan="4"><input type="radio" name="section" value="0"> No Block To Choose From</td>
							  </tr>';
			}
			
		}elseif($data == FALSe)
		{
		
		}
		
		echo $template;
	}
}
